<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option label="请选择" :value="null"></el-option>
          <el-option label="已开启" :value="0"> </el-option>
          <el-option label="已关闭" :value="1"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="40" label="供应商名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:designator:add']"
          >新增</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="designatorList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="ID" width="55" align="center" prop="id" />
      <el-table-column label="供应商名称" align="center" prop="name" />
      <el-table-column label="供应商简称" align="center" prop="abName" />
      <el-table-column
        label="统一社会信用代码"
        align="center"
        prop="socialCreditCode"
      />
      <el-table-column label="负责人" align="center" prop="responsible" />
      <el-table-column label="电话" align="center" prop="phoneNumber" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-switch
            :value="scope.row.status == '0'"
            @change="changeStatus(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column
        width="220px"
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-refresh-left"
            @click="handleResetPass(scope.row)"
            v-hasPermi="['system:designator:edit']"
            >重置密码</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleAccount(scope.row)"
            v-hasPermi="['system:designator:remove']"
            >账号管理</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:designator:edit']"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 重置密码dialog -->
    <el-dialog
      title="重置密码"
      :visible.sync="resetPassword.visible"
      width="20%"
      center
    >
      <div style="text-align: center">重置后，默认密码为123456</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetPassword.visible = false">取 消</el-button>
        <el-button type="primary" @click="resetPassword.visible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  listOrders,
  delDesignator,
  updateOrders,
} from "@/api/service/purchase/supplier.js";
export default {
  name: "Designator",
  data() {
    return {
      // 重置密码是否展示
      resetPassword: {
        visible: false,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品--主标号表格数据
      designatorList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        name: null,
        oneCategoryId: null,
        twoCategoryId: null,
        threeCategoryId: null,
      },
      // 表单参数
      form: {},
      form1: {}, // 预拌混凝土
      form2: {}, // 预拌砂浆
      categoryList1: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 开关
    changeStatus(item) {
      const form = { ...item };
      // 改变状态
      form.status = form.status == "0" ? 1 : 0;
      updateOrders(form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        item.status = form.status;
        //this.getList();
      });
    },
    /** 查询产品--主标号列表 */
    getList() {
      this.loading = true;
      listOrders(this.queryParams).then((response) => {
        this.designatorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        oneCategoryId: null,
        twoCategoryId: null,
        threeCategoryId: null,
        categoryInfoId: null,
        name: null,
        plasticHoldingTime: null,
        intensityRating: null,
        benchmarkPrice: null,
        content: null,
        status: 0,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };

      this.form1 = {
        pldh: null,
        pmdh: null,
        bgmd: null,
        dldykzddj: null,
        kzddjykzzj: null,
        kdf: null,
        mdf: null,
        ksdj: null,
        klsydj: null,
        kllzstdj: null,
        kllzstdjdtlf: null,
        kthxndj: null,
        zmsxndjyxn: null,
        tsxs: null,
        kzdj: null,
        gmddj: null,
        xsldj: null,
        fhdj: null,
      };
      this.form2 = {
        pldh: null,
        pmdh: null,
        bgmd: null,
        cd: null,
        bsl: null,
        kdxqdssl: null,
        kdxzlssl: null,
        njlsqd: null,
        ssl: null,
        ksdj: null,
      };

      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      //   this.open = true;
      //   this.title = "新增主标号";
      this.$router.push({
        path: "/urchase/supplier/edit",
      });
    },
    /* 重置密码*/
    handleResetPass(row) {
      console.log(row);
      this.resetPassword.obj = row;
      this.resetPassword.visible = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push({
        path: `/urchase/supplier/edit?id=${row.id}`,
      });
    },
    // 账号管理
    handleAccount(row) {
      this.$router.push({
        path: `/purchase/supplier/account?id=${row.id}&name=${row.name}`,
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除产品--主标号编号为"' + ids + '"的数据项？')
        .then(function () {
          return delDesignator(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.edit-form {
  // display: flex;
  .form-label {
    font-size: 14px;
    font-weight: bold;
    line-height: 36px;
    padding-right: 30px;
    .form-red {
      color: #d23c26;
    }
  }
  .form-value {
    display: flex;
    //gap: 30px;
  }
}

::v-deep .el-tabs__content {
  max-height: 500px;
  overflow: auto;
}

.row-item {
  display: flex;
  // gap: 20px;
}
::v-deep .el-form-item__label {
  // width: 240px;
  text-align: right;
}
.form-right ::v-deep .el-input {
  width: 200px;
}
</style>